package com.zhiteng.service.impl;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhiteng.entity.CourseNode;
import com.zhiteng.entity.TimeTable;
import com.zhiteng.mapper.CourseNodeMapper;
import com.zhiteng.mapper.TimeTableMapper;
import com.zhiteng.service.TimeTableService;

@Service
public class TimeTableServiceImpl implements TimeTableService {

	@Autowired
	private TimeTableMapper timeTableMapper;

	@Autowired
	private CourseNodeMapper courseNodeMapper;

	@Override
	public int saveTimeTable(TimeTable timeTable) {
		return timeTableMapper.insertSelective(timeTable);
	}

	@Override
	public Set<String> queryAllTimeTable(String schoolId) {

		CourseNode record = new CourseNode();
		record.setSchool_id(schoolId);
		List<CourseNode> list = courseNodeMapper.select(record);

		Set<String> list2 = new HashSet<>();

		for (CourseNode courseNode : list) {
			list2.add(courseNode.getCourse_name());
		}

		return list2;
	}

	@Override
	public List<TimeTable> queryTimeTableBySubject(String subject, String schoolId) {
		TimeTable record = new TimeTable();
		record.setSubject(subject);
		record.setSchoolId(schoolId);
		List<TimeTable> list = timeTableMapper.select(record);
		return list;
	}

	@Override
	public int deleteTimeTableBySubject(String schoolId, String subject) {
		TimeTable record = new TimeTable();
		record.setSchoolId(schoolId);
		record.setSubject(subject);
		return timeTableMapper.delete(record);
	}

	@Override
	public Set<String> queryAllTimeTable2(String schoolId) {
		TimeTable record = new TimeTable();
		record.setSchoolId(schoolId);
		List<TimeTable> list = timeTableMapper.select(record);
		Set<String> set = new HashSet<>();
		for (TimeTable timeTable : list) {
			set.add(timeTable.getSubject());
		}
		return set;
	}

	@Override
	public List<TimeTable> queryAllTimeTable3(String schoolId) {
		TimeTable record = new TimeTable();
		record.setSchoolId(schoolId);
		List<TimeTable> list = timeTableMapper.select(record);
		return list;
	}

	@Override
	public int updateTimeTableType(TimeTable timeTable) {
		return timeTableMapper.updateByPrimaryKey(timeTable);
	}

	@Override
	public void deleteTimeTable(String schoolId) {
		TimeTable record = new TimeTable();
		record.setSchoolId(schoolId);
		timeTableMapper.delete(record);
	}
}
